package logic

import (
	"baidutieba/models/mysql"
	"baidutieba/tiebarpc/internal/svc"
	"baidutieba/tiebarpc/tiebarpc"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type TieBaAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewTieBaAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TieBaAddLogic {
	return &TieBaAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *TieBaAddLogic) TieBaAdd(in *tiebarpc.TieBaAddRequest) (*tiebarpc.TieBaAddResponse, error) {
	// todo: add your logic here and delete this line

	ba := mysql.TieBa{
		Title:   in.Title,
		Image:   in.Image,
		Class:   in.Class,
		Num:     in.Num,
		Context: in.Context,
		UserId:  in.UserId,
	}
	mysql.DB.Create(&ba)
	return &tiebarpc.TieBaAddResponse{
		Id: int64(ba.ID),
	}, nil
}
